<?php

namespace app\home\controller;

use app\common\controller\Home;

class Search extends Home
{
	public function index()
	{
		$param = zanpiancms_param_url();
		config('params', array('wd' => $param['wd'], 'p' => '[PAGE]'));
		$channel = $this->Lable_Search($param);
		if ($this->request->isAjax() && !empty($param['sid'])) {
			return $this->fetch(DS . $channel['search_skin'] . '_ajax');
		} else {
			if (!empty($GLOBALS['config']['system']['system_search_time'])) {
				if ($param['p'] == 1 && get_time("last_searchtime") < $GLOBALS['config']['system']['system_search_time']) {
					return $this->error("请不要频繁操作，搜索时间间隔为" . $GLOBALS['config']['system']['system_search_time'] . "秒");
					exit;
				}
			}
			return $this->fetch(DS . $channel['search_skin']);
		}
	}
	// 联想搜索
	public function vod()
	{
		$wd = htmlspecialchars(input('q/s', ''));
		$limit = !empty($Url['limit']) ? $Url['limit'] : '10';
		$where['vod_name|vod_letters|vod_aliases'] = array('like', $wd . '%');
		$rs = db('vod');
		$data = $rs->field('vod_id,vod_cid,vod_pic,vod_pic,vod_gold,vod_area,vod_content,vod_continu,vod_actor,vod_title,vod_language,vod_filmtime,vod_director,vod_year,vod_name,vod_title,vod_letters,vod_addtime')->where($where)->limit($limit)->order('vod_addtime desc')->select();
		$count = $rs->where($where)->count('vod_id');
		if ($data) {
			foreach ($data as $key => $val) {
				$list['data'][$key]['vod_name'] = $val['vod_name'];
				$list['data'][$key]['vod_title'] = $val['vod_title'];
				$list['data'][$key]['vod_url'] = zanpian_read_url('home/vod/read', $val);
			}
			return json(['data' => $list['data'], 'info' => 'ok', 'status' => 1]);
		} else {
			return json(['data' => $data, 'info' => 'ok', 'status' => 0]);
		}
	}
	// 联想搜索
	public function ajax()
	{
		$Url = param_url();
		$limit = !empty($Url['limit']) ? $Url['limit'] : '10';
		$where['vod_name|vod_letters|vod_aliases'] = array('like', $Url['wd'] . '%');
		$rs = db('vod');
		$data = $rs->field('vod_id,vod_cid,vod_pic,vod_pic,vod_gold,vod_area,vod_content,vod_continu,vod_actor,vod_title,vod_language,vod_filmtime,vod_director,vod_year,vod_name,vod_title,vod_letters,vod_addtime')->where($where)->limit($limit)->order('vod_addtime desc')->select();
		$count = $rs->where($where)->count('vod_id');
		if ($data) {
			foreach ($data as $key => $val) {
				$data[$key]['list_id'] = $val['vod_cid'];
				$data[$key]['list_name'] = getlistname($val['vod_cid'], 'list_name');
				$data[$key]['list_url'] = getlistname($val['vod_cid'], 'list_url');
				$data[$key]['vod_readurl'] = zanpian_read_url('home/vod/read', $val);
				$data[$key]['vod_picurl'] = zanpian_img_url($val['vod_pic']);
			}
			return jsonp($data);
		}
	}
}
// +----------------------------------------------------------------------
// | ZanPianCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.zanpian.com All rights reserved.
// +----------------------------------------------------------------------
// | BBS:  <http://www.feifeicms.cc>
// +----------------------------------------------------------------------
